<template>
  <div>
    <!-- 轮播图 -->
    <el-carousel :interval="4000" type="card" height="500px">
      <el-carousel-item v-for="(image, index) in images" :key="index">
        <img
          :src="image.src"
          alt="电视剧图片"
          class="carousel-image"
          @click="showVideo(index)"
        />
      </el-carousel-item>
    </el-carousel>

    <!-- 视频播放区域 -->
    <div v-if="isVideoVisible" class="video-overlay" @click.self="hideVideo">
      <div class="video-container">
        <video :src="videoUrl" controls autoplay class="video-player"></video>
        <button class="close-btn" @click="hideVideo">关闭</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      images: [
        { src: require('@/assets/电视剧1.jpg'), video: require('@/assets/sp1.mp4') },
        { src: require('@/assets/电视剧2.jpg'), video: require('@/assets/sp2.mp4') },
        { src: require('@/assets/电视剧3.jpg'), video: require('@/assets/sp3.mp4') }
      ],
      isVideoVisible: false,
      videoUrl: null
    };
  },
  methods: {
    showVideo(index) {
      this.videoUrl = this.images[index].video;
      this.isVideoVisible = true;
    },
    hideVideo() {
      this.isVideoVisible = false;
      this.videoUrl = null; // 停止视频播放
    }
  }
};
</script>

<style scoped>
.carousel-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
}

/* 视频遮罩层 */
.video-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

/* 视频容器 */
.video-container {
  position: relative;
  max-width: 75%;
  max-height: 75%;
}

/* 视频播放器样式 */
.video-player {
  width: 100%;
  height: auto;
  border-radius: 8px;
}

/* 关闭按钮 */
.close-btn {
  margin-top: 10px;
  padding: 10px 20px;
  font-size: 16px;
  color: white;
  background-color: #ff4d4f;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
</style>